Yacon.component.TSqlGridFoot = function(element){
	this.element = element;
	this.page = this.element.page;
	this.pageNo = this.element.pageNo;
	this.recordNo = this.element.recordNo;
	this.bottomModel = this.element.bottomModel;
};

Yacon.component.TSqlGridFoot.prototype = {

	/* 获取底部HTML信息 */	
	getHtml: function(){
		
		var html = "";

		//页码部分
		html += "<div style='float:right;'>";
		
		html += "<nav aria-label='Page navigation'>";	
			
		html += "<ul class='pagination pagination-sm'>";
		
		html += this.getPageHtml(); 
		
		html += "<div class='input-page-div'>";
		
		if(this.bottomModel == "all"){
			
			html += "<select class='lily-page-record-select' name='lily-page-record-no'>";
			
			for(var i=10;i<=100;){
				
				if(i == this.pageSize){
					html += "<option value='"+i+"' selected>"+i+"条/页</option>";
				}else{
					html += "<option value='"+i+"'>"+i+"条/页</option>";
				}		
				
				i = i+10;
			}
			
			html += "</select>";
			
		}
		
		if(this.bottomModel == "all" || this.bottomModel == "middle"){
			
			html += "&nbsp;&nbsp;&nbsp;&nbsp;到第&nbsp;&nbsp;&nbsp;&nbsp;";
			
			html += "<input class='lily-page-direction-no' type='text' maxlength='6' value='1'>";
			
			html += "&nbsp;&nbsp;&nbsp;页&nbsp;&nbsp;&nbsp;";
			
			if($("body").hasClass("mid")){
	            html += "<button type='button' class='btn btn-default lily-button-form lily-page-direction-btn' style='height:27px;'>跳转</button>";
			}else{
				html += "<button type='button' class='btn btn-default lily-button-form lily-page-direction-btn' style='height:19px;'>跳转</button>";
			}
			
		}
		
		
		if(this.bottomModel == "easy"){
			html += "<div style='padding-top: 5px;'>";
			html += "&nbsp;&nbsp;&nbsp;&nbsp;共<strong>&nbsp;"+this.recordNo+"&nbsp;</strong>条&nbsp;&nbsp;&nbsp;";
			html += "</div>";
		}
		else{
			html += "&nbsp;&nbsp;&nbsp;&nbsp;共<strong>&nbsp;"+this.recordNo+"&nbsp;</strong>条&nbsp;&nbsp;&nbsp;";
		}
		
		
		html += "</div>";
		  	
		html += "</ul>"; 
		
		html += "</nav>";		
		html += "</div>";
		
		html += "<div style='clear:both;'></div>";
			
		return html;
		
	},
	
	getPageHtml: function(){
		
		var html = "";
		
		//上一页
		html += "<li>";  		
		html += "<a href='javascript:;' aria-label='Previous'>";  
		if(this.page == 1){
			html += "<span class='click-disable prev-page' aria-hidden='true'>上一页</span>";
		}else{
			html += "<span class='click-enable prev-page' aria-hidden='true'>上一页</span>";
		}
		
		html += "</a>";
		html += "</li>"; 
		
		//低于7页
		if(this.pageNo <= 7){
			
			for(var i=1;i<=this.pageNo;i++){
				
				if(this.page == i){
					html += "<li><a href='javascript:;' class='lily-page active click-enable'>"+i+"</a></li>";
				}else{
					html += "<li><a href='javascript:;' class='lily-page click-enable'>"+i+"</a></li>";
				}
					
			}
			
		}
		
		//高于7页
		else{
			
			//当前第1页
			if(this.page >= 1 && this.page <= 5){
				
				for(var i=1;i<=5;i++){
					
					if(this.page == i){
						html += "<li><a href='javascript:;' class='lily-page active click-enable'>"+i+"</a></li>";
					}else{
						html += "<li><a href='javascript:;' class='lily-page click-enable'>"+i+"</a></li>";
					}
						
				}
				
				html += "<li><a href='javascript:;' class='lily-page click-disable'>...</a></li>";
				html += "<li><a href='javascript:;' class='lily-page click-enable'>"+this.pageNo+"</a></li>";
			}
			
			//当前最后1页
			else if(this.page >= (this.pageNo-4) && this.page <= this.pageNo){
				
				html += "<li><a href='javascript:;' class='lily-page click-enable'>1</a></li>";
				html += "<li><a href='javascript:;' class='lily-page click-disable'>...</a></li>";
				
				for(var i=4;i>=0;i--){
					
					if(this.page == (this.pageNo - i)){
						html += "<li><a href='javascript:;' class='lily-page active click-enable'>"+(this.pageNo-i)+"</a></li>";
					}else{
						html += "<li><a href='javascript:;' class='lily-page click-enable'>"+(this.pageNo-i)+"</a></li>";
					}
						
				}
				
			}
			
			//其他情况
			else{
				
				//前半部分
				html += "<li><a href='javascript:;' class='lily-page click-enable'>1</a></li>";
				html += "<li><a href='javascript:;' class='lily-page click-disable'>...</a></li>";
				html += "<li><a href='javascript:;' class='lily-page click-enable'>"+(this.page-1)+"</a></li>";	
				
				
				html += "<li><a href='javascript:;' class='lily-page active click-enable'>"+this.page+"</a></li>";
				
				//后半部分
				html += "<li><a href='javascript:;' class='lily-page click-enable'>"+(this.page+1)+"</a></li>";	
				html += "<li><a href='javascript:;' class='lily-page click-disable'>...</a></li>";
				html += "<li><a href='javascript:;' class='lily-page click-enable'>"+this.pageNo+"</a></li>";
				
			}
			
		}
		
		//下一页
		html += "<li>";  		
		  	
		if(this.page == this.pageNo){
			html += "<a href='javascript:;' class='click-disable next-page' aria-label='Next'>";
			html += "<span aria-hidden='true'>下一页</span>";
		}else{
			html += "<a href='javascript:;' class='click-enable next-page' aria-label='Next'>";
			html += "<span aria-hidden='true'>下一页</span>";
		}		
		html += "</a>";
		html += "</li>"; 
		
		return html;
		
	},
	
	/* 绑定动作 */
	addEvent:function(){
		
		var parent = this.parent;
		var search = this.parent.page.element.search + " div[lily-id='"+this.parent.elementID+"'][lily-type='"+this.parent.elementType+"']";
		var self = this;
		
		//上一页
		$(search+" .lily-table-foot .pagination .prev-page.click-enable ").unbind("click");
		$(search+" .lily-table-foot .pagination .prev-page.click-enable ").click(function(){
						
			var pageBefore = self.page;
			if(pageBefore != 1){
				pageBefore -- ;
			}
			
			self.pageSize = $(search+" .lily-table-foot .pagination .lily-page-record-select").find("option:selected").val();
			
			self.parent.dataSet.setBody("pageSize",self.pageSize);
			self.parent.dataSet.setBody("absolutePage",pageBefore);		
			self.parent.dataSet.refresh();
			
		});
		
		//下一页
		$(search+" .lily-table-foot .pagination .next-page.click-enable ").unbind("click");
		$(search+" .lily-table-foot .pagination .next-page.click-enable ").click(function(){
						
			var pageAfter = self.page;
			if(pageAfter != self.pageNo){
				pageAfter ++ ;
			}
			
			self.pageSize = $(search+" .lily-table-foot .pagination .lily-page-record-select").find("option:selected").val();
			
			self.parent.dataSet.setBody("pageSize",self.pageSize);
			self.parent.dataSet.setBody("absolutePage",pageAfter);		
			self.parent.dataSet.refresh();
			
		});
		
		//页码
		$(search+" .lily-table-foot .pagination .lily-page.click-enable ").unbind("click");
		$(search+" .lily-table-foot .pagination .lily-page.click-enable ").click(function(){
			
			var curPageNo = $(this).html();
			
			self.pageSize = $(search+" .lily-table-foot .pagination .lily-page-record-select").find("option:selected").val();
			
			self.parent.dataSet.setBody("pageSize",self.pageSize);
			self.parent.dataSet.setBody("absolutePage",curPageNo);		
			self.parent.dataSet.refresh();
			
		});
		
		//确定方式页面跳转		
		$(search+" .lily-table-foot .pagination .lily-page-direction-btn ").unbind("click");
		$(search+" .lily-table-foot .pagination .lily-page-direction-btn ").click(function(){
			
			var value = $(search+" .lily-table-foot .pagination .lily-page-direction-no").val();
			
			var curPageNo = 1;
			
			if(value == undefined){
				curPageNo = 1;
			}else{				
				var curPageNo = parseInt(value);				
				if (isNaN(curPageNo)){ curPageNo = 1;}			
			}
			
			self.pageSize = $(search+" .lily-table-foot .pagination .lily-page-record-select").find("option:selected").val();
			
			self.parent.dataSet.setBody("pageSize",self.pageSize);
			self.parent.dataSet.setBody("absolutePage",curPageNo);		
			self.parent.dataSet.refresh();
			
		});
		
		//复合变化
		$(search+" .lily-table-foot .pagination .lily-page-record-select ").unbind("change");
		$(search+" .lily-table-foot .pagination .lily-page-record-select ").change(function(){
			
			self.pageSize = $(search+" .lily-table-foot .pagination .lily-page-record-select").find("option:selected").val();
			
			self.parent.dataSet.setBody("pageSize",self.pageSize);
			self.parent.dataSet.setBody("absolutePage",1);		
			self.parent.dataSet.refresh();
			
		});
		
		
	},
	
	/* 刷新信息 */
	refresh:function(){
		
		this.element = this.parent.view.grid.bottom;
		this.page = this.element.page;
		this.pageNo = this.element.pageNo;
		this.recordNo = this.element.recordNo;
		//this.pageSize = this.parent.view.grid.pageSize;
		
		var parent = this.parent;
		var search = this.parent.page.element.search + " div[lily-id='"+this.parent.elementID+"'][lily-type='"+this.parent.elementType+"']";
		var self = this;
		
		$(search+" .lily-table-foot").empty();	
		$(search+" .lily-table-foot").append(this.getHtml());
		
	},
	
	/* 重置初始信息  */
	reset:function(){
		
		this.page = 1;
		this.pageNo = 1;
		this.recordNo = 0;
		this.pageSize = 30;
		
		var parent = this.parent;
		var search = this.parent.page.element.search + " div[lily-id='"+this.parent.elementID+"'][lily-type='"+this.parent.elementType+"']";
		var self = this;
		
		$(search+" .lily-table-foot").empty();	
		$(search+" .lily-table-foot").append(this.getHtml());
	}
		
};